<template>
	<div class="system-dialog-container">
		<el-dialog :title="state.dialog.title" v-model="state.dialog.isShowDialog" width="450px" :close-on-click-modal="false">
			<el-form ref="recordDialogFormRef" :model="state.ruleForm" size="default" label-width="90px">
				<el-row :gutter="35">
					<el-col :xs="24" class="mb20">
						<el-form-item label="支付方式">
							<el-select v-model="state.ruleForm.payment" placeholder="请选择支付方式" clearable size="default" class="w100">
								<el-option v-for="(item,key) in state.payData" :key="key" :label="item" :value="key"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :xs="24" class="mb20">
						<el-form-item label="收款账号">
							<el-input v-model="state.ruleForm.pay_username" placeholder="请输入收款账号" clearable></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" class="mb20">
						<el-form-item label="付款状态">
							<el-select v-model="state.ruleForm.status" placeholder="请选择状态" clearable size="default" class="w100">
								<el-option label="付款中" :value="1"></el-option>
								<el-option label="已付款" :value="2"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="onCancel" size="default">取 消</el-button>
					<el-button type="primary" @click="onSubmit" size="default">{{ state.dialog.submitTxt }}</el-button>
				</span>
			</template>
		</el-dialog>
	</div>
</template>

<script setup name="recordDialog">
import { reactive, ref } from 'vue';

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh']);
import { remitApi } from '/@/api/remit/index';
// 定义变量内容
const recordDialogFormRef = ref();
const state = reactive({
	payData:{
		// 1:'微信',
		// 2:'支付宝',
		// 3:'银行卡',
		4:'Paypal',
    },
	ruleForm: {
		status: '',
		id:0,
		pay_username:'',
		payment:''
	},
	dialog: {
		isShowDialog: false,
		title: '随机核减',
		submitTxt: '提交',
	},
});

// 打开弹窗
const openDialog = (data) => {
	state.dialog.isShowDialog = true;
	state.ruleForm = {
		status: data.status,
		id: data.id,
		pay_username: data.pay_username,
		payment: data.payment
	}
};
// 关闭弹窗
const closeDialog = () => {
	state.dialog.isShowDialog = false;
};
// 取消
const onCancel = () => {
	closeDialog();
};
// 提交
const onSubmit = () => {
	remitApi().edit(state.ruleForm).then(async res=>{
		closeDialog(); // 关闭弹窗
		emit('refresh');
	})
};

// 暴露变量
defineExpose({
	openDialog,
	state
});
</script>
